package com.fjw.mapper;

import com.fjw.pojo.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {
    //新增
    @Insert("insert into Article(title,content,job_category,major_category,author) values (#{title},#{content},#{job_category},#{major_category},#{author})")
    void add(Article article);

    //通过ID查找
    @Select("select * from Article where id=#{id}")
    Article findById(Integer id);

    //通过类别查找
    @Select("select * from Article where job_category=#{job_category} and major_category=#{major_category}")
    List<Article> findByCategory(String job_category, String major_category);
    @Select("select * from Article where job_category=#{job_category}")
    List<Article> findByJobCategory(String job_category);
    @Select("select * from Article where major_category=#{major_category}")
    List<Article> findByMajorCategory(String major_category);

    //通过作者查找
    @Select("select * from Article where author=#{author}")
    List<Article> findByAuthor(Integer author);

    //通过ID删除
    @Delete("delete from Article where id=#{id}")
    void deleteById(Integer id);

    //通过ID更新
    @Update("update Article set title=#{title},content=#{content},job_category=#{job_category},major_category=#{major_category} where id=#{id} ")
    void updateById(Article article);

    //展示全部文章
    @Select("select * from Article")
    List<Article> getAll();

}
